import App from './App'
import uView from '@/uni_modules/uview-ui'
import myConfig from './my_config.js'
import myData from './my_data.js'

Vue.use(uView)

Vue.prototype.myData=myData
Vue.prototype.myConfig=myConfig


Vue.prototype.goTo=function(path){
	uni.navigateTo({
		url:path
	})
}

Vue.prototype.utils={
  dateString:function(date){
    return date.getFullYear()+"-"+(date.getMonth()+1).toString().padStart(2,'0')+"-"+date.getDate().toString().padStart(2,'0')
  },
  timeString:function(time){
    return time.getFullYear()+"-"+(time.getMonth()+1).toString().padStart(2,'0')+"-"+time.getDate().toString().padStart(2,'0')+" "
    +time.getHours().toString().padStart(2,'0')+":"+time.getMinutes().toString().padStart(2,'0')+":"+time.getSeconds().toString().padStart(2,'0')
  }
}

Vue.prototype.API=function(obj){
	/*showLoading showWhenCode1 url method data code0*/
	if(!obj.hasOwnProperty('showLoading'))
		obj.showLoading=false
	if(!obj.hasOwnProperty('showWhenCode1'))
		obj.showWhenCode1=true
	if(!obj.hasOwnProperty('method'))
		obj.method='GET'
	if(obj.showLoading)
		uni.showLoading()
	
	uni.request({
		url:myConfig.apiBaseUrl+myConfig.apiProxy+obj.url,
		method:obj.method,
		data:obj.data,
		header:{
			auth:myData.token
		},
		success:function(res){
			if(obj.showLoading)
				uni.hideLoading()
			if(res.data.code==0){
				obj.code0(res)
			}else{
				if(obj.showWhenCode1){
					uni.showToast({
						icon:'none',
						title:res.data.message
					})
				}
			}
		},
		fail:function(){
			if(obj.showLoading)
				uni.hideLoading()
			uni.showToast({
				title:"系统繁忙，稍后再试！",
				icon:"error"
			})
		}
	})
}





// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif